import { ref } from "vue"
import type { Ref } from "vue"
import { useRouter, useRoute } from "vue-router"
import { getDetail } from "@/api/detail"
type detailType = {
    price: {
        basicPrice: number,
        counterPrice: number | null
    },
    listPicUrl: string,
    name: string,
    goodCmtRate: string
}
export function useNavBar() {
    let router = useRouter()
    const onSearch = function () {
        router.push("/search")
    }
    const onShopping = function () {
        router.push("/shoppingcart")
    }
    const onHome = function () {
        router.push("/home")
    }
    const toLogin = function () {
        location.href = "https://m.you.163.com/u/login?callback=https%3A%2F%2Fm.you.163.com%2Fucenter"
    }
    return {
        onSearch, onHome, onShopping, toLogin
    }
}

export function useDetail() {
    let route = useRoute()
    let id = route.params.id
    let detalArr: Ref<Array<detailType>> = ref([])
    getDetail({
        csrf_token: "40d9d966a116291c04abbd2b15ede374",
        __timestamp: 1677572025884,
        id: id as any
    }).then(res => {
        detalArr.value = res.data.item
        console.log(detalArr);

    })

    return {
        detalArr
    }
}